<Query Kind="Program" />

void Main()
{
	Context context = new Context(new ConcreteStateA());
	context.Condition = 1;
	context.Request();
	context.Condition = 2;
	context.Request();
}

abstract class State
{
	public abstract void Handle(Context context);
}

class ConcreteStateA : State
{
	public override void Handle(Context context)
	{
		if(context.Condition == 2){
			context.State = new ConcreteStateB();
			context.Request();
		} else {
			Console.WriteLine("Handle() in A");
		}
	}
}

class ConcreteStateB : State
{
	public override void Handle(Context context)
	{
		if (context.Condition == 1)
		{
			context.State = new ConcreteStateA();
			context.Request();
		}
		else
		{
			Console.WriteLine("Handle() in B");
		}
	}
}

class Context
{
	public State State { get; set; }
	public int Condition { get; set; }
	public Context(State state)
	{
		State = state;
	}

	public void Request()
	{
		State.Handle(this);
	}
}